<template>
	<!-- 商品列表无头的 -->
	<!-- 首页环球狗粮 -->
	<view class="body"> 
		<view class="nav">
			<!-- <view @click="selected" class="lefat"> 
				<text :class="currentTab==0 ? 'active' : ''" @tap="swichNav">销量优先</text>
			</view>
			<view @click="selected1" class="righta">
				<text :class="currentTab==1 ? 'active' : ''" @tap="swichNav">价格</text>
				<view class="icon">
					<image src="../../static/splbiao/bottom-arrow.png" :class="jiageqhuan==0" @tap="swichNav" class="img_1"></image>
					<image src="../../static/splbiao/bottom-arrow.png" :class="jiageqhuan==1"  @tap="swichNav" class="img_2"></image>
				</view>
			</view> -->
		</view>
		<view class="list">
			<view class="listBor" v-for="(item,index) in shopListes" @tap="tabpar(item)" :key="index">
				<view class="listBorTop">
					<image :src='item.img' class="img_3"></image>
				</view>
				<view class="listBorBot_one nowrap">
					{{item.title}}
				</view>
				<view class="listBorBot_two">
					<view class="num">￥{{item.price /100}} </view>
					<view class="money">已售{{item.sales}}件 </view>
				</view>
			</view>
			<view class="load">
				{{loadText}}
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	export default {
		data() {
			return {
				textOne: true,
				status: 1,
				shopListes: [],
				shopName: '',
				loadText: '没有更多数据了',
				// tab切换
				jiages: 0,
				jiageqhuan:0,
				ide : '',
			}
		},
		onShow(){
			if (uni.getStorageSync('accessToken') == '') {
				uni.showModal({
					title: '登录提示',
					content: '您尚未登录，是否立即登录',
					success: function(res) {
						if (res.confirm) {
							uni.navigateTo({
								url: '../long/long'
							})
							return
						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				});
			}
		},
		onLoad(dxians) {
			if (dxians.tid != null) {
				console.log(dxians)
				this.ide = dxians.tid
				console.log(this.ide)
					uni.request({
						url: 'http://192.168.1.54:8081/m.api?_gp=goods&_mt=getGoodsPage&pageNo=&pageSize=&categoryId='+this.ide+'&orderBy=&isAsc=&title=',
						success: res => {
							console.log(res)
							this.shopListes = res.data.data.items
						}
					})
			} else if(dxians.goods != null){
				var list = JSON.parse(dxians.goods)
				this.shopName = dxians.name
				this.shopListes = list
				this.selected()
			}else if (dxians.data != null){
				console.log(dxians.data)
				this.shopName = dxians.data
				this.selected()
			}else if(dxians.iid != null){
				var list = JSON.parse(dxians.iid)
				this.ide = list
				console.log(this.ide)
				this.selected()
			}else if (dxians.url != null){
				var list = JSON.parse(dxians.url)
				this.ide = Number(list)
				this.selected()
			}else if (dxians.pages != null){
				var list = JSON.parse(dxians.pages)
				this.ide = Number(list)
				console.log(this.ide)
				this.selected()
			}
		},
		onPullDownRefresh() {
			// console.log('refresh');
			var that = this
			this.loadText = "上拉显示更多数据"
			setTimeout(function() {
				that.loadText = "没有更多数据了"
				uni.stopPullDownRefresh();
			}, 500);
		},
		methods: {
			//销量优先
			selected(){
				let that = this
				   uni.request({
				   	url: 'http://192.168.1.54:8081/m.api?_gp=goods&_mt=getGoodsPage&pageNo=1&pageSize=100000&categoryId='+this.ide+'&orderBy=sales&isAsc=&title='+this.shopName+'',
				   	success: res => {
				   		that.shopListes = res.data.data.items
				   	},
				   })
				   this.jiages = 0
			  },
			  selected1(){ 
				  //价格
				 var that = this
				 that.textOne = !that.textOne
				 uni.request({
				 	url: 'http://192.168.1.54:8081/m.api?_gp=goods&_mt=getGoodsPage&pageNo=&pageSize=&categoryId='+this.ide+'&orderBy=price&isAsc='+this.textOne+'&title='+this.shopName+'',
				 	success: res => {
						console.log(res,'666')
				 		that.shopListes =res.data.data.items
				 	},
				 }),
				 this.jiages = 1
				 if (this.jiageqhuan == 0) {
				 	this.jiageqhuan = 1
				 } else{
				 	this.jiageqhuan = 0
				 }
			  },
			// swichNav: function(e) {
			// 	// console.log(e);
			// 	var that = this;
			// 	if (this.jiages === e.target.dataset.jiageqhuan) {
			// 		return false;
			// 	} else {
			// 		this.jiages = e.target.dataset.jiageqhuan
			// 	}
			// },
			tabpar(item){
				let id = item.id
				uni.navigateTo({
					url: '/pages/details/producte?dataset='+id+'&num=1',
				})
			}
		}


	};
</script>

<style scoped="scoped">
	.icon {display: flex;position: absolute;top:2rpx;left: 212rpx;font-size: 30rpx;align-items: center}
	.nav {width: 100%;height: 100rpx;background-color: #F8F8F8;box-shadow: 0 1px 5px rgb(0 0 0 / 6%);}
	.img_1{
		width: 30rpx; height: 30rpx;position: absolute;
		top: 20rpx;transform: rotate(182deg);left: 20rpx;
	}
	.img_2{
		width: 30rpx; height: 30rpx;
		position: absolute;top: 45rpx;left: 20rpx;
	}
	.lefat {line-height: 100rpx;text-align: center;flex: 1;color: #000;font-weight: bold;font-size: 28rpx;}
	.num {float: left;color: #FA436A;font-size: 30rpx;line-height: 40rpx;}
	.money {float: right;color: #909399;font-size: 23rpx;line-height: 48rpx;}
	.img_3 {width: 100%;height: 100%;}
	.righta {line-height: 100rpx;text-align: center;flex: 1;position: relative;font-weight: bold;font-size: 28rpx;}
	.active {border-bottom: 4rpx solid #fc5558;color: #fc5558;padding: 26rpx;}
	.colora {color: #fc5558}
	.show {display: block;text-align: center;line-height: 200rpx;}
	.hidden {display: none;text-align: center;line-height: 200px;}
	.list {width: 100%;margin: auto;margin-top: 15rpx;}
	.listBor {width: 350rpx;height: 420rpx;float: left;margin-left: 19rpx;}
	.listBorTop {width: 100%;height: 310rpx;float: left;display: flex;justify-content: center;align-items: center;}
	.listBorBot_one {width: 100%;height: 40rpx;float: left;line-height: 40rpx;font-size: 30rpx;}
	.listBorBot_two {width: 100%;height: 40rpx;float: left;}
	.nowrap {white-space: nowrap;white-space: nowrap;text-overflow: ellipsis;overflow: hidden;padding: 12rpx 0;}
	.load {width: 100%;height: 100rpx;float: left;text-align: center;line-height: 100rpx;font-size: 25rpx;color: #777777;}
</style>
